package com.spsy.pay.listener;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import com.spsy.api.common.vo.Pay2OrderNotifyVo;
import com.spsy.order.api.OrderApi;
import com.spsy.pay.domain.PaymentOrder;
import com.spsy.pay.mapper.PaymentOrderMapper;
import com.spsy.pay.service.IPaymentOrderService;
import com.spsy.pay.vo.ASHLDHFLAJSKDFVO;
import com.spsy.pay.vo.OWJEDFKPqwjle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: liuzhiping
 * @date: 2025/6/9 15:41
 **/
@Component
@Slf4j
@RabbitListener(queues = "2210a_queue_a1")
public class ConstomerListener {


    @Autowired
    private IPaymentOrderService iPaymentOrderService;

    @Autowired
    private OrderApi orderApi;

    @RabbitHandler
    public void handle(String str , Message message, Channel channel){
        log.info("接受消息----str：{}",str);

        ExecutorService executorService = Executors.newFixedThreadPool(5);
        //8小时
        ASHLDHFLAJSKDFVO ow =  JSON.parseObject(str,ASHLDHFLAJSKDFVO.class);

        String orderNo = ow.getOrderNo();
        long status  = Long.parseLong(ow.getStatus());


        executorService.submit(()->{

            //2：把状态修改成已支付  1s
            int updateCount = iPaymentOrderService.updatePaymentOrderByOrderNo(PaymentOrder.builder().orderNo(orderNo).status(status).build());

            //2s
            this.orderApi.notifyOrderStatus(Pay2OrderNotifyVo.builder().orderNo(orderNo).status(status+"").build());

            //调用电信的接口发送短信
            //对象 对象 = JSON.parse(str，对象.c)；
            //根据订单号修改订单状态。
        });


    }
}
